/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.nyquistmeteocal.boundary;

import it.nyquistmeteocal.entity.CalendarEvents;
import java.security.Principal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author gatb27
 */
@Stateless
public class CalendarEventsManager {
    
    @PersistenceContext
    public EntityManager cm;
    
    @Inject
    Principal principal;
    
    
    public void saveCalendarEvents(CalendarEvents calendarevents) {
        cm.persist(calendarevents);     
    }
    
    public void deleteCalendarEvents(CalendarEvents calendarevents) {
        cm.remove(calendarevents);
    }
    
    public Connection getConnection() {
        Connection con = null;

        String url = "jdbc:mysql://localhost:3306/nyreg";
        String user = "root";
        String password = "root";
        try {
            con = DriverManager.getConnection(url, user, password);
            System.out.println("Connection completed. ");
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        } finally {
        }
        return con;
    }
    
}
